layui.use(['form','laypage', 'layer','table','upload'], function(){
    var laypage = layui.laypage
        ,form = layui.form
        ,table = layui.table
        ,upload = layui.upload;
    laypage.render({
        elem: 'data_fill_page'
        ,count: 1000
        ,layout: ['limit', 'prev', 'page', 'next']
    });

    form.on('submit(add-collect-btn)', function(data){
        layerActive.gotoAddDataCollect();
        return false; //阻止表单跳转。如果需要表单跳转，去掉这段即可。
    });
    form.on('select(trade-type-btn)', function(data){
        console.log(data); //得到select原始DOM对象
        return false; //阻止表单跳转。如果需要表单跳转，去掉这段即可。
    });
    form.on('select(publish-depart)', function(data){//发布部门
        console.log(data); //得到select原始DOM对象
        return false; //阻止表单跳转。如果需要表单跳转，去掉这段即可。
    });
    //展示已知数据
    table.render({
        elem: '#add-notice-table'
        ,cols: [[ //标题栏
            {type:'checkbox',title: '全选',}
            ,{field: 'username', title: '汇总表名称', minWidth: 250,templet: '#typeTpl',rowspan:'2'}
            ,{field: 'experience', title: '报告期类别', edit: 'text',align:'center',rowspan:'2'}
            ,{field: 'experience', title: '报告期', edit: 'text',align:'center',rowspan:'2'}
            ,{field: 'experience', title: '表号', edit: 'text',align:'center',rowspan:'2'}
            ,{title: '附件', edit: 'text',align:'center',toolbar: '#barDemo'}
        ]]
        ,data: [
            {
                "id": "10001"
                ,"username": "医院"
                ,"email": "130"
                ,"sex": "20"
                ,"city": "30"
                ,"sign": "100"
                ,"experience": "116"
                ,"ip": "192.168.0.8"
                ,"logins": "108"
                ,"joinTime": "2016-10-14"
                ,"level":1
            }, {
                "id": "10002"
                ,"username": "  综合医院"
                ,"email": "130"
                ,"sex": "20"
                ,"city": "30"
                ,"sign": "100"
                ,"experience": "116"
                ,"ip": "192.168.0.8"
                ,"logins": "108"
                ,"joinTime": "2016-10-14"
                ,"level":2
            }, {
                "id": "10003"
                ,"username": "  中西医结合医院"
                ,"email": "130"
                ,"sex": "20"
                ,"city": "30"
                ,"sign": "100"
                ,"experience": "116"
                ,"ip": "192.168.0.8"
                ,"logins": "108"
                ,"joinTime": "2016-10-14"
                ,"level":2
            }, {
                "id": "10004"
                ,"username": "  专科医院"
                ,"email": "130"
                ,"sex": "20"
                ,"city": "30"
                ,"sign": "100"
                ,"experience": "116"
                ,"ip": "192.168.0.8"
                ,"logins": "108"
                ,"joinTime": "2016-10-14"
                ,"level":2
            }, {
                "id": "10005"
                ,"username": "   口腔医院"
                ,"email": "130"
                ,"sex": "20"
                ,"city": "30"
                ,"sign": "100"
                ,"experience": "116"
                ,"ip": "192.168.0.8"
                ,"logins": "108"
                ,"joinTime": "2016-10-14"
                ,"level":3
            }, {
                "id": "10006"
                ,"username": "   眼科医院"
                ,"email": "130"
                ,"sex": "20"
                ,"city": "30"
                ,"sign": "100"
                ,"experience": "116"
                ,"ip": "192.168.0.8"
                ,"logins": "108"
                ,"joinTime": "2016-10-14"
                ,"level":3
            }, {
                "id": "10007"
                ,"username": "肿瘤医院"
                ,"email": "130"
                ,"sex": "20"
                ,"city": "30"
                ,"sign": "100"
                ,"experience": "116"
                ,"ip": "192.168.0.8"
                ,"logins": "108"
                ,"joinTime": "2016-10-14"
                ,"level":3
            }, {
                "id": "10008"
                ,"username": "心血管病医院"
                ,"email": "130"
                ,"sex": "20"
                ,"city": "30"
                ,"sign": "100"
                ,"experience": "116"
                ,"ip": "192.168.0.8"
                ,"logins": "108"
                ,"joinTime": "2016-10-14"
                ,"level":3
            }
        ]
        //,skin: 'line' //表格风格
        ,even: true
        //,page: true //是否显示分页
        //,limits: [5, 7, 10]
        //,limit: 5 //每页默认显示的数量
    });
    //触发弹窗事件
    var layerActive = {//弹框方法
        open_upload_layer:function(){//上传附件
            layer.open({
                type: 1
                ,title: '上传附件' //不显示标题栏
                ,closeBtn: true
                ,area: '500px;'
                ,shade: 0.5
                ,id: 'layerUpload' //设定一个id，防止重复弹出
                ,btn: ['确定', '取消']
                ,btnAlign: 'c'
                ,moveType: 1 //拖拽模式，0或者1
                ,content: $(".layer-upload").html()
                ,success: function(layero){
                    var btn = layero.find('.layui-layer-btn');
                    // btn.find('.layui-layer-btn0').attr({
                    //     href: 'manage/reportImport.html'
                    //     ,target: '_blank'
                    // });
                }
            });

            //拖拽上传
            upload.render({
                elem: '.upload-file'
                ,url: 'XXX'
                ,accept: 'file' //普通文件
                ,done: function(res){
                    console.log(res)
                }
            });
        },
        openlayer_add_notice:function(){//发布公告
            layer.open({
                type: 1
                ,title: '发布公告' //不显示标题栏
                ,closeBtn: true
                ,area: '500px;'
                ,shade: 0.5
                ,id: 'layer_add_notice' //设定一个id，防止重复弹出
                ,btn: ['确定', '取消']
                ,btnAlign: 'c'
                ,moveType: 1 //拖拽模式，0或者1
                ,content: $(".layer-add-notice")
                ,success: function(layero){
                    var btn = layero.find('.layui-layer-btn');
                    // btn.find('.layui-layer-btn0').attr({
                    //     href: 'manage/reportImport.html'
                    //     ,target: '_blank'
                    // });
                }
            });
        }

    };

    $('.add-notice-table .layui-btn').on('click', function(){//执行弹框事件
        var othis = $(this), method = othis.data('method');
        layerActive[method] ? layerActive[method].call(this, othis) : '';
    });
    $(".submit-add-notice").on('click', function(){//执行弹框事件
        layerActive.openlayer_add_notice();
    });

});
